package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    void insert(Orders orders);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 根据id查询订单详情
     * @param id
     * @return
     */
    @Select("select  * from orders where  id = #{id}")
    Orders selectById(Long id);


    /**
     * 历史订单查询
     * @param dto
     * @return
     */
    Page<Orders> selectWithPage(OrdersPageQueryDTO dto);

    /**
     * 根据状态统计订单数量
     * @param status
     */
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);

    /**
     * 订单已经过了15分钟的取消操作
     * @param status
     * @param time
     * @return
     */
    @Select("select * from orders where status = #{status} and order_time < #{time} ")
    List<Orders> selectStatusAndTime(Integer status, LocalDateTime time);


    @Select("select * from orders where number = #{orderNumber}")
    Long selectByNumberId(String orderNumber);

    /**
     * 营业额统计
     * @return
     */
    Double selectStatistics(Map map);

    /**
     * 订单数统计
     * @param map
     * @return
     */
    Integer countId(Map map);



}
